package com.ecmcloud.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.ecmcloud.config.exception.BusinessException;
import com.ecmcloud.config.exception.LoginExpiredException;

@Slf4j
@Component
@RestControllerAdvice
public class GlobalExceptionHandler {
	
    @ExceptionHandler(BusinessException.class)
    public Object businessExceptionHandler(BusinessException e){
        log.error("BusinessException：",e);
        return com.ecmcloud.common.dto.Result.fail(e.getMessage());
    }
    
    @ExceptionHandler(LoginExpiredException.class)
    public Object loginExpiredExceptionHandler(LoginExpiredException e){
        log.error("LoginExpiredException：",e);
        return com.ecmcloud.common.dto.Result.fail(e.getMessage());

    }

    @ExceptionHandler(RuntimeException.class)
    public Object runtimeExceptionHandler(RuntimeException e){
        log.error("RuntimeException：",e);
        return com.ecmcloud.common.dto.Result.fail(e.getMessage());
    }
}
